<?php
/**
 * WithdrawController.class.php
 * 提现控制器
 * 
 * @author  王中艺 <wangzy_smile@qq.com>
 * @date    2017-08-28
 */

namespace Attach\Controller;

class WithdrawController extends BaseController {

    /**
     * 数据列表获取
     * @param   $condition
     * @param   $p
     * @return  $list and $page_html
     */
    function getList(){
        $condition  = $this->request('condition', []);
        $condition['target_id'] = $this->userId;
        $page   = $this->request('p', 1);
        $pageHtml   = true;

        $this->response([
            'list'  => D('Withdraw')->getList($condition, $page, $pageHtml),
            'page_html' => $pageHtmml,
            'sql'   => D('Withdraw')->getLastSql()
        ]);
    }

    /**
     * 初审条目
     * @param   $id
     * @param   $result
     * @param   $remark
     * @return  boolean
     */
    function firstAudit(){
        $client     = $this->unEmptyParams(['id', 'result']);
        $result     = $client['result'];
        $remark     = $this->request('remark');
        
        $model  = new \Think\Model();
        $model->startTrans();
        try{
            D('Withdraw')->firstAudit($client['id'], $result, $remark, $this->userId);
            $model->commit();
        }catch(\Exception $e){
            $model->rollback();
            $this->response($e->getMessage(), -1);
        }
        
        $this->response();
    }

    /**
     * 复审条目
     * @param   $id
     * @param   $result
     * @param   $remark
     * @return  boolean
     */
    function secondAudit(){
        $client     = $this->unEmptyParams(['id', 'result']);
        $result     = $client['result'];
        $remark     = $this->request('remark');

        $model  = new \Think\Model();
        $model->startTrans();
        try{
            D('Withdraw')->secondAudit($client['id'], $result, $remark, $this->userId);
            $model->commit();
        }catch(\Exception $e){
            $model->rollback();
            $this->response($e->getMessage(), -1);
        }

        $this->response();
    }
}